package com.gopay.common.cps.dao.bank.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.bank.BisBankBusProdDAO;
import com.gopay.common.domain.bis.BisBankBusProd;

/**
 * @BisBankBusProdDAOImpl.java
 * @author wanggang
 * @2013-12-27 下午4:07:54 www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("bisBankBusProdDAO")
public class BisBankBusProdDAOImpl extends BaseDAOImpl<BisBankBusProd, String> implements BisBankBusProdDAO {

    /* (non-Javadoc)
     * @see com.gopay.common.cps.dao.bank.BisBankBusProdDAO#getBisBankBusProdCount()
     */
    @Override
    public int getBisBankBusProdCount() {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("del", false);
        String hql = "select count(*) from BisBankBusProd where del = :del";
        return findCountByHql(hql, params);
    }

    /* (non-Javadoc)
     * @see com.gopay.common.cps.dao.bank.BisBankBusProdDAO#getBisBankBusProd(int, int)
     */
    @Override
    public List<BisBankBusProd> getBisBankBusProd(int pageNo, int pageSize) {
        String hql = "from BisBankBusProd t where del = :del order by t.bankProdCode";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("del", false);
        return findByHql(hql, params, pageNo, pageSize);
    }

    @Override
    public BisBankBusProd findbyBankProdCode(String bankProdCode) {
        DetachedCriteria criteria = DetachedCriteria.forClass(BisBankBusProd.class);
        criteria.add(Restrictions.eq("bankProdCode",bankProdCode));
        criteria.add(Restrictions.eq("del",false));
        List<BisBankBusProd> list = this.findByCriteria(criteria);
        return list.size()>0 ? list.get(0): null;
    }

    @Override
    public List<BisBankBusProd> getAllBisBankBusProd() {
        String hql = "from BisBankBusProd t where del = :del order by t.bankProdCode";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("del", false);
        return findByHql(hql, params);
    }

	@Override
	public List<BisBankBusProd> findAll() {
		StringBuilder s = new StringBuilder("from BisBankBusProd b where 1 = 1");
		s.append(" and b.del=:del");
		s.append(" and b.enable=:enable");
		
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("del", false);
		param.put("enable", true);
		
		return findByHql(s.toString(), param);
	}
}
